#include "form_programwashpara.h"
#include "ui_form_programwashpara.h"
#include "serialportusr.h"
#include <cstdlib>


extern SerialPortUsr * g_serial_port_pt;

Form_ProgramWashPara::Form_ProgramWashPara(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form_ProgramWashPara)
{
    ui->setupUi(this);
}

Form_ProgramWashPara::~Form_ProgramWashPara()
{
    delete ui;
}

void Form_ProgramWashPara::on_pushButton_back_clicked()
{
   close();
}

void Form_ProgramWashPara::on_pushButton_save_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 13 00 02 00 30 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);

}

void Form_ProgramWashPara::on_pushButton_new_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 14 00 02 00 30 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);

}

void Form_ProgramWashPara::on_pushButton_num_clicked()
{

}

void Form_ProgramWashPara::on_pushButton_name_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 30 ";
    for (int i = 0;i < ui->lineEdit_name->text().length();i++) {
            temp_c = ui->lineEdit_name->text().at(i).toLatin1();
            sprintf(tempa,"%x",temp_c);
            temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}

void Form_ProgramWashPara::on_pushButton_channel_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 2D 11 ";
    for (int i = 0;i < ui->lineEdit_channel->text().length();i ++) {
      temp_c = ui->lineEdit_channel->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}

void Form_ProgramWashPara::on_pushButton_times_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 2E 11 ";
    for (int i = 0;i < ui->lineEdit_times->text().length();i ++) {
      temp_c = ui->lineEdit_times->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}

void Form_ProgramWashPara::on_pushButton_volume_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 09 11 ";
    for (int i = 0;i < ui->lineEdit_volume->text().length();i ++) {
      temp_c = ui->lineEdit_volume->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}

void Form_ProgramWashPara::on_pushButton_board_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 0D 11 ";
    for (int i = 0;i < ui->lineEdit_board->text().length();i ++) {
      temp_c = ui->lineEdit_board->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}

void Form_ProgramWashPara::on_pushButton_shakeTimeH_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 37 11 ";
    for (int i = 0;i < ui->lineEdit_shakeTimeH->text().length();i ++) {
      temp_c = ui->lineEdit_shakeTimeH->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);

}

void Form_ProgramWashPara::on_pushButton_shakeTimeM_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 38 11 ";
    for (int i = 0;i < ui->lineEdit_shakeTimeM->text().length();i ++) {
      temp_c = ui->lineEdit_shakeTimeM->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}

void Form_ProgramWashPara::on_pushButton_shakeTimeS_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 39 11 ";
    for (int i = 0;i < ui->lineEdit_shakeTimeS->text().length();i ++) {
      temp_c = ui->lineEdit_shakeTimeS->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);

}

void Form_ProgramWashPara::on_pushButton_shakeAmplitude_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 14 11 ";
    for (int i = 0;i < ui->lineEdit_shakeAmplitude->text().length();i ++) {
      temp_c = ui->lineEdit_shakeAmplitude->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);

}

void Form_ProgramWashPara::on_pushButton_soakTimeH_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 3A 11 ";
    for (int i = 0;i < ui->lineEdit_soakTimeH->text().length();i ++) {
      temp_c = ui->lineEdit_soakTimeH->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}

void Form_ProgramWashPara::on_pushButton_soakTimeM_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 3B 11 ";
    for (int i = 0;i < ui->lineEdit_soakTimeM->text().length();i ++) {
      temp_c = ui->lineEdit_soakTimeM->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}

void Form_ProgramWashPara::on_pushButton_soakTimeS_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 3C 11 ";
    for (int i = 0;i < ui->lineEdit_soakTimeS->text().length();i ++) {
      temp_c = ui->lineEdit_soakTimeS->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}

void Form_ProgramWashPara::on_pushButton_pressure_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 0B 11 ";
    for (int i = 0;i < ui->lineEdit_pressure->text().length();i ++) {
      temp_c = ui->lineEdit_pressure->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);

}

void Form_ProgramWashPara::on_pushButton_suckTimeS_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 0F 11 ";
    for (int i = 0;i < ui->lineEdit_suckTimeS->text().length();i ++) {
      temp_c = ui->lineEdit_suckTimeS->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}

void Form_ProgramWashPara::on_pushButton_injectTimeS_clicked()
{
    QString temp_qstr;
    char temp_c;
    char tempa[5];

    temp_qstr="EE B1 11 00 02 00 40 11 ";
    for (int i = 0;i < ui->lineEdit_injectTimeS->text().length();i ++) {
      temp_c = ui->lineEdit_injectTimeS->text().at(i).toLatin1();
      sprintf(tempa,"%x",temp_c);
      temp_qstr.append(tempa).append(" ");
    }
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}
